package conceptualization;

import java.util.*;
import java.io.*;

public class ProResult {
	public int qIndex;
	public String query; 
	public int times;
	public String orgConcept;
	public String orgEntity;
	public ArrayList<String> termList;
	public ArrayList<Integer> conceptList;
	public ArrayList<String> typList;
	
	public ProResult(int qIndex, String query, int times, String orgConcept, String orgEntity) {
		this.qIndex = qIndex;
		this.query = query;
		this.times = times; 
		this.orgConcept = orgConcept;
		this.orgEntity = orgEntity;
		this.termList = new ArrayList<String>();
		this.conceptList = new ArrayList<Integer>();
		this.typList = new ArrayList<String>();
	}
	
	public void addPartition(String info) {
		String[] tmp = info.split("\\t");
//		if (tmp.length == 3) // need to deal with more typical condition
//			this.addPartition(tmp[0], Integer.parseInt(tmp[1]), tmp[2]);
		if (tmp.length >= 3) {
			for (int i = 2; i < tmp.length; i+= 2) {
				try {
					this.addPartition(tmp[0], Integer.parseInt(tmp[i-1]), tmp[i]);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	/************
	 * Add one partition to result
	 * @param term matched instance
	 * @param conIndex concept index being matched
	 * @param typical typicality of the matched concept
	 */
	public void addPartition(String term, int conIndex, String typical) {
		this.termList.add(term);
		this.conceptList.add(conIndex);
		this.typList.add(typical);
	}
	
	public boolean canConceptualized() {
		return termList.size() != 0;
	}
	
	public String info() {
		String ans = qIndex + "\t";
		ans += query + "\t"
			 + times + "\t"
			 + orgConcept + "\t"
			 + orgEntity + "\t";
		int end = termList.size();
		ans += end;
		for (int i = 0; i < end; i++) {
			ans += "\t\r\n" + termList.get(i) + "\t" + conceptList.get(i) + "\t" + typList.get(i);
		}
		return ans;
	}
	
}
